package mypractice;

import java.util.Arrays;

public class Leetcode414 {
    public int thirdMax(int[] nums) {
        Arrays.sort(nums);
        int len=nums.length-2;
        int count=2;
        while(len>=0&&count>0){
            if(nums[len]==nums[len+1]){
                len--;
            }else{
                len--;
                count--;
            }
        }
        if(count==0){
            return nums[len+1];
        }
        return nums[nums.length-1];
    }



    //本方法未解决有相同值得问题；
    /*public int thirdMax(int[] nums) {
        if(nums.length<3){
            if(nums.length==1){
                return nums[0];
            }else{
                return nums[0]<nums[1]?nums[1]:nums[0];
            }
        }
        int[] arr=new int[3];
        arr=getThreeSor(nums[0],nums[1],nums[2] );
        int i;
        for(i=3;i<nums.length;i++){
            if(nums[i]>arr[0]){
                arr[0]=nums[i];
                arr=getThreeSor(arr[0],arr[1],arr[2] );
            }
        }
        return arr[0];
    }

    public int[] getThreeSor(int a,int b,int c){
        int[] arr = new int[3];
        arr[0]=a;
        arr[1]=b;
        arr[2]=c;
        Arrays.sort(arr);
        return arr;
    }*/


}
